var app = angular.module("myapp", []);
app.controller("mycontroller", function($scope, $http) {
	$scope.detail = [];
	$scope.count = 1;
	$scope.goodlist=[];
	$http({
		url: "getDetail",
		method: "POST",
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}).success(function(res) {
		$scope.detail = res.data[0];
	}).error(function(err) {
		console.log(err);
	})
	
	$scope.settype = function(goodtype){
		$scope.type = goodtype;
	}
	$scope.jian = function(){
		if($scope.count>1){
			$scope.count--;
		}
		
	}
	$scope.jia = function(){
		$scope.count++;
	}
	
	$scope.join = function(){
		if($scope.count<1 || goodtype==""){
			$(".shopwrong").show();
		}else{
			$http({
				url: "addshopcar",
				method: "POST",
				data:"goodid="+$scope.detail.id+"&count="+$scope.count+"&type="+goodtype,
				headers:{
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}).success(function(res) {
				if(res.status==1){
					$(".shopinfo-success").show();
					$(".shopwrong").hide();
					$scope.getshopcar();
				}else{
					$(".shopwrong").html("请登录后，添加购物车");
					$(".shopwrong").show();
				}
			}).error(function(err) {
				console.log(err);
			})
		}
	}
	$scope.getshopcar = function(){
		$http({
			url: "getshopcar",
			method: "POST",
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}).success(function(res) {
			$(".header-num").html(res.data.length);
		   	if(res.data.length>0){
		   		$(".header-cartshow-text").html("去购物车并结算");
		   		$scope.goodlist=res.goodinfo;
		   	}
		}).error(function(err) {
			console.log(err);
		})
	}
	$scope.getshopcar();
	
	$http({
		url: "getuserlove",
		method: "POST",
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}).success(function(res) {
	   	$scope.lovelist=res;
	}).error(function(err) {
		console.log(err);
	})
	
	$http({
		url: "gethotgood",
		method: "POST",
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}).success(function(res) {
	   	$scope.hotlist=res;
	}).error(function(err) {
		console.log(err);
	})
	
	
})
var goodtype = "";

$(".detail-scrollsmall").on("mouseenter",".detail-smallimg img",function(){
	$(".big1").attr("src",$(this).attr("src"));
	$(".detail-smallimg img").css("border-color","#dcdcdc");
	$(this).css("border-color","#B1544F");
})

$(".detail-spec").on("click",".detail-number",function(){
	$(".detail-number").css({"border":"1px solid #ccc"})
	$(this).css({"border":"1px solid #b1544f"});
	goodtype = $(this).html();
})

$(".goonshop").click(function(){
	$(".shopinfo-success").hide();
})


// 点击TAB
$(".detail-span1").click(function(){
	$(".detail-shserver").css("display","block");
	$(".detail-span1").addClass("detail-borbom");
	$(".detail-span").removeClass("detail-borbom");
});
$(".detail-span").click(function(){
	$(".detail-shserver").css("display","none");
	$(".detail-span").addClass("detail-borbom");
	$(".detail-span1").removeClass("detail-borbom");
});



